package com.competition;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * 找到一个字符串中的所有的长度为3的回文字符串
 */
public class CountPalindromicSubsequence {
    public static void main(String[] args) {

        String s = "bbcbaba";

        Set<String> sets = new HashSet<String>();

       int len = s.length();

       for (int i=0;i<len;i++){
           for (int j=i+2;j<len;j++){
                if(s.charAt(i) == s.charAt(j)){
                    for(int k=i+1;k<j;k++){
                        String str = s.charAt(i) + "" + s.charAt(k) + "" + s.charAt(j) +"";
                        sets.add(str);
                    }
                }
           }
       }
        System.out.println(sets.size());
        Iterator<String> iterator = sets.iterator();
       while(iterator.hasNext()){
           System.out.println(iterator.next());
       }


    }
}
